home *** CD-ROM | disk | FTP | other *** search
- /*
-
- SystemFolder XFCN
-
- © 1990 Apple Computer, Inc.; by Mike Byrne
-
- This XFCN returns the full pathname of the currently active System Folder.
-
- Form:
- SystemFolder()
-
-
- # the MPW 3.2 build commands
- C -b SystemFolder.c -mbg off
- Link -w -t STAK -c WILD -rt XFCN=601 ∂
- -m ENTRYPOINT ∂
- -sg SystemFolder ∂
- SystemFolder.c.o ∂
- "{Libraries}HyperXLib.o" ∂
- "{Libraries}Runtime.o" ∂
- "{Libraries}Interface.o" ∂
- "{CLibraries}StdCLib.o" ∂
- -o "some stack"
- */
-
- #include <Types.h>
- #include <OSUtils.h>
- #include <Files.h>
- #include <string.h>
- #include <strings.h>
- #include <Memory.h>
- #include "HyperXCmd.h"
-
- #define NULL 0L
- #define NIL 0L
-
- #define kNumParams 0
-
- /* prototypes */
- void ErrorBack(XCmdPtr paramPtr, char *message);
- void MoveLockParams ( XCmdPtr paramPtr, short paramCount );
- void UnlockParams ( XCmdPtr paramPtr, short paramCount );
-
-
- pascal void EntryPoint(XCmdPtr paramPtr)
- {
- SysEnvRec theWorld;
- CInfoPBRec pBlck;
- short volID;
- char pathName[256];
- char cDummy[128];
- Str255 pasDummy;
-
-
- /* move high and lock the parameters. */
- MoveLockParams(paramPtr, paramPtr->paramCount);
-
- /* check for copyright or syntax help request */
- if (!strcmp( (char*)*paramPtr->params[0], "!") ) {
- ErrorBack(paramPtr, "v1.1, ©1990 Apple Computer, Inc.; by Mike Byrne");
- UnlockParams(paramPtr, paramPtr->paramCount);
- return;
- } else if (!strcmp ( (char*)*paramPtr->params[0], "?") ) {
- ErrorBack(paramPtr, "SystemFolder syntax is 'SystemFolder()'");
- UnlockParams(paramPtr, paramPtr->paramCount);
- return;
- }
-
-
- /* check for correct number of parameters */
- if (paramPtr->paramCount != kNumParams) {
- ErrorBack(paramPtr, "SystemFolder syntax is 'SystemFolder()'");
- UnlockParams(paramPtr, paramPtr->paramCount);
- return;
- }
-
- /* set strings to zero */
- pathName[0] = '\0';
- cDummy[0] = '\0';
- pasDummy[0] = '\0';
-
- /* get the ref number for the system folder */
- if (SysEnvirons(2, &theWorld)) {
- ErrorBack(paramPtr, "Can't find the System Folder");
- return;
- } else {
- volID = theWorld.sysVRefNum;
- }
-
- /* set up pBlck stuff */
- pBlck.dirInfo.ioNamePtr = &pasDummy;
- pBlck.dirInfo.ioVRefNum = volID;
- pBlck.dirInfo.ioFDirIndex = 1;
- pBlck.dirInfo.ioDrDirID = 0;
-
- /* get the first directory ID (if we can't, then errorback. */
- if ( PBGetCatInfo(&pBlck, false) != noErr ) {
- ErrorBack(paramPtr, "Cannot get System file info");
- return;
- }
-
- /* now, keep going up the tree things we reach the top */
- while (pBlck.dirInfo.ioDrDirID != 2) {
-
- /* swap id's from the parent ID to the current ID and reset the index. */
- pBlck.dirInfo.ioDrDirID = pBlck.dirInfo.ioDrParID;
- pBlck.dirInfo.ioFDirIndex = -1;
-
- /* get load the NamePtr (which is equal to pasDummy) and build the C string. */
- if (!PBGetCatInfo(&pBlck, false)) {
- p2cstr(pasDummy);
- strcpy( cDummy, pasDummy );
- strcat(cDummy, ":");
- strcat(cDummy, pathName);
- strcpy(pathName, cDummy);
-
- } else {
- /* this is just in case the PB call fails. */
- ErrorBack(paramPtr, "Cannot get System parent info");
- return;
- }
- }
-
-
- /* the pathName string should now be fully built. we're outta here. */
- ErrorBack(paramPtr, pathName);
-
- }
-
-
-
- /* ++++ ErrorBack ++++
- allocate and load up paramPtr->returnValue with a string
- -------------------------------------------------------- */
- void ErrorBack(XCmdPtr paramPtr, char *message)
- {
- Handle mesHnd;
-
- /*
- Allocate space for an error message.
- Copy the string into it.
- Return the handle to HyperCard.
- */
- mesHnd = NewHandle((long)(strlen(message)+1));
- if (mesHnd == nil) return;
- strcpy((char *)*mesHnd,message);
- paramPtr->returnValue = mesHnd;
- }
-
-
- /* move high and lock down all parameters
- ----------------------------------------------------------------------- */
- void MoveLockParams ( XCmdPtr paramPtr, short paramCount )
- {
- short i;
-
- for(i=0; i <= paramCount-1; i++)
- {
- MoveHHi(paramPtr->params[i]);
- HLock(paramPtr->params[i]);
- }
- }
-
-
-
-
- /* unlock all parameter handles in the XCmdBlock
- --------------------------------------------- */
- void UnlockParams ( XCmdPtr paramPtr, short paramCount )
- { short i;
-
- for(i=0; i <= paramCount-1; i++)
- { HUnlock(paramPtr->params[i]);}
- }
-